package com.my.kq.controller;

import com.my.kq.entity.Employee;
import com.my.kq.service.EmployeeService;
import com.my.kq.service.LesveService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/LeaveAdd")
public class LeaveAdd extends HttpServlet {
    private EmployeeService EmployeeService=new EmployeeService();
    private LesveService lesveService=new LesveService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            req.setCharacterEncoding("utf-8");
            resp.setCharacterEncoding("utf-8");
            resp.setContentType("text/html;charset=utf-8");
            HttpSession session = req.getSession();
            Employee cook =(Employee) session.getAttribute("cook");
            Integer id = cook.getId();
            Employee yee= EmployeeService.Empcx(id);
            //员工编号
            Integer number = yee.getDepartment_number();
            //获取信息
            //开始时间
            String start = req.getParameter("start");
            //结束时间
            String end = req.getParameter("end");
            //类型
            String type = req.getParameter("type");
            //原因
            String reason = req.getParameter("reason");

            //获取天数
            Tshu t = new Tshu();
            int tshu = t.tshu(start, end);
            session.setAttribute("tshu",tshu);

           int num= lesveService.leaveadd(number,start,end,type,reason,tshu);
                   if(num>0){
              req.getRequestDispatcher("jsp/welcome.jsp").forward(req,resp);
                      }


            // lesveService.leaveadd();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
